<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/11/9
 * Time: 17:32
 */

namespace app\mall\service;


use app\mall\model\User;

class LoginService extends BaseService
{
    protected $user;

    public function __construct()
    {
        $this->user = new User();
    }

    public function accountLogin($account, $password)
    {
        $user = $this->user->where('account', $account)->with('merchant')->find();
        if (!$user) return $this->messge(0, '账号不存在');
        if ($user['merchant']['audit_status'] !== 1) return $this->messge(0, '该账号还在审核中');
        if ($user['merchant']['is_show'] !== 1) return $this->messge(0, '该账号被禁用');
        $user = $this->user->where('account', $account)->where('password', md5($password))->with('merchant')->find();
        if (!$user) return $this->messge(0, '密码不正确');
        return $this->messge(1, $user);
    }

    /**
     * @param $code
     * @param string $msg
     * @return array|string
     * 返回提示
     */
    public function messge($code, $msg = '')
    {
        $msg = [
            'code' => $code,
            'msg' => $msg,

        ];
        return $msg;
    }

}